load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load(":generate_file.bzl", "generate_file")

package(default_visibility = ["//visibility:public"])

# Retrieve the module name and version.
_MODULE_NAME = "pinocchio"
_MODULE_VERSION = "2.6.21"

# Define the required headers to be generated.
generate_file(
    name = "config_header",
    out = "include/pinocchio/config.hpp",
    library_name = _MODULE_NAME,
    library_version = _MODULE_VERSION,
    template = "cmake/config.hh.cmake",
)

generate_file(
    name = "deprecated_header",
    out = "include/pinocchio/deprecated.hpp",
    library_name = _MODULE_NAME,
    library_version = _MODULE_VERSION,
    template = "cmake/deprecated.hh.cmake",
)

generate_file(
    name = "warning_header",
    out = "include/pinocchio/warning.hpp",
    library_name = _MODULE_NAME,
    library_version = _MODULE_VERSION,
    template = "cmake/warning.hh.cmake",
)

filegroup(
    name = "pinocchio_models",
    srcs = glob(["models/**/*"]),
)

cc_library(
    name = "pinocchio_includes",
    srcs = glob(["src/**/*.cpp"]),
    hdrs = glob(
        [
            "include/**/*.hpp",
            "include/**/*.hxx",
        ],
        exclude = ["include/pinocchio/bindings/**/*"],
    ) + [
        ":config_header",
        ":deprecated_header",
        ":warning_header",
    ],
    copts = ["-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR"],
    includes = ["include/"],
    deps = [
        "@boost.serialization//:boost.serialization",
        "@boost.filesystem//:boost.filesystem",
        "@boost.iostreams//:boost.iostreams",
        "@boost.integer//:boost.integer",
        "@boost.foreach//:boost.foreach",
        "@boost.fusion//:boost.fusion",
        "@boost.math//:boost.math",
        "@boost.asio//:boost.asio",
        "@boost.variant//:boost.variant",
        "@boost.algorithm//:boost.algorithm",
        "@boost.type_traits//:boost.type_traits",
        "@boost.bind//:boost.bind",
        "@boost.format//:boost.format",
        "@boost.property_tree//:boost.property_tree",
        "@eigen//:eigen",
        "@sdformat//:urdf_parser",
    ],
)

BINARY_DEPS = [
    ":pinocchio_includes",
    "@eigen//:eigen",
]

# Core examples
cc_binary(
    name = "inverse-kinematics",
    srcs = ["examples/inverse-kinematics.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "overview-simple",
    srcs = ["examples/overview-simple.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "overview-lie",
    srcs = ["examples/overview-lie.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "overview-SE3",
    srcs = ["examples/overview-SE3.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "interpolation-SE3",
    srcs = ["examples/interpolation-SE3.cpp"],
    deps = BINARY_DEPS,
)

# Urdf-based examples
cc_binary(
    name = "overview-urdf",
    srcs = ["examples/overview-urdf.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "build-reduced-model",
    srcs = ["examples/build-reduced-model.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "geometry-models",
    srcs = ["examples/geometry-models.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "kinematics-derivatives",
    srcs = ["examples/kinematics-derivatives.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "forward-dynamics-derivatives",
    srcs = ["examples/forward-dynamics-derivatives.cpp"],
    deps = BINARY_DEPS,
)

cc_binary(
    name = "inverse-dynamics-derivatives",
    srcs = ["examples/inverse-dynamics-derivatives.cpp"],
    deps = BINARY_DEPS,
)

TEST_DEPS = [
    ":pinocchio_includes",
    "@boost.test//:boost.test",
    "@eigen//:eigen",
]

COMMON_TEST_HEADERS = [
    "unittest/utils/macros.hpp",
    "unittest/utils/model-generator.hpp",
]

cc_test(
    name = "aba-derivatives_test",
    srcs = ["unittest/aba-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "aba_test",
    srcs = ["unittest/aba.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "algo-check_test",
    srcs = ["unittest/algo-check.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "all-joints_test",
    srcs = ["unittest/all-joints.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "cartesian-product-liegroups_test",
    srcs = ["unittest/cartesian-product-liegroups.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "center-of-mass-derivatives_test",
    srcs = ["unittest/center-of-mass-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "centroidal-derivatives_test",
    srcs = ["unittest/centroidal-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "centroidal_test",
    srcs = ["unittest/centroidal.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "cholesky_test",
    srcs = ["unittest/cholesky.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "com_test",
    srcs = ["unittest/com.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "compute-all-terms_test",
    srcs = ["unittest/compute-all-terms.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "constraint_test",
    srcs = ["unittest/constraint.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "contact-dynamics-derivatives_test",
    srcs = ["unittest/contact-dynamics-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "contact-dynamics_test",
    srcs = ["unittest/contact-dynamics.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "copy_test",
    srcs = ["unittest/copy.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "crba_test",
    srcs = ["unittest/crba.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "data_test",
    srcs = ["unittest/data.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "eigen-basic-op_test",
    srcs = ["unittest/eigen-basic-op.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "eigen-tensor_test",
    srcs = ["unittest/eigen-tensor.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "energy_test",
    srcs = ["unittest/energy.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "explog_test",
    srcs = ["unittest/explog.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "finite-differences_test",
    srcs = ["unittest/finite-differences.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "frames-derivatives_test",
    srcs = ["unittest/frames-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "frames_test",
    srcs = ["unittest/frames.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-composite_test",
    srcs = ["unittest/joint-composite.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-configurations_test",
    srcs = ["unittest/joint-configurations.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-free-flyer_test",
    srcs = ["unittest/joint-free-flyer.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-generic_test",
    srcs = ["unittest/joint-generic.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-jacobian_test",
    srcs = ["unittest/joint-jacobian.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-mimic_test",
    srcs = ["unittest/joint-mimic.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-planar_test",
    srcs = ["unittest/joint-planar.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-prismatic_test",
    srcs = ["unittest/joint-prismatic.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-revolute_test",
    srcs = ["unittest/joint-revolute.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-spherical_test",
    srcs = ["unittest/joint-spherical.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "joint-translation_test",
    srcs = ["unittest/joint-translation.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "kinematics-derivatives_test",
    srcs = ["unittest/kinematics-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "kinematics_test",
    srcs = ["unittest/kinematics.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "liegroups_test",
    srcs = ["unittest/liegroups.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "macros_test",
    srcs = ["unittest/macros.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "model_test",
    srcs = ["unittest/model.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "quaternion_test",
    srcs = ["unittest/quaternion.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "regressor_test",
    srcs = ["unittest/regressor.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "rnea-derivatives_test",
    srcs = ["unittest/rnea-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "rnea-second-order-derivatives_test",
    srcs = ["unittest/rnea-second-order-derivatives.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "rnea_test",
    srcs = ["unittest/rnea.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "rotation_test",
    srcs = ["unittest/rotation.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "rpy_test",
    srcs = ["unittest/rpy.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "sample-models_test",
    srcs = ["unittest/sample-models.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "symmetric_test",
    srcs = ["unittest/symmetric.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "vector_test",
    srcs = ["unittest/vector.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "version_test",
    srcs = ["unittest/version.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)

cc_test(
    name = "visitor_test",
    srcs = ["unittest/visitor.cpp"] + COMMON_TEST_HEADERS,
    deps = TEST_DEPS,
)
